<?php
/**
 * Created by PhpStorm.
 * User: zjx
 * Date: 2016/11/25
 * Time: 10:32
 */

namespace App\Services\Utils;


class SafeMakeDir
{
    /**
     * @param $dir_path
     * @param int $mode
     * @param bool $recursive
     * @return bool
     */
    public static function makeDir($dir_path, $mode = 0777, $recursive = true)
    {
        if (is_dir($dir_path)) {
            return true;
        }

        return mkdir($dir_path, $mode, $recursive);
    }
    /**
     * @param $file_path
     * @param int $mode
     * @param bool $recursive
     * @return bool
     */
    public static function makeFileDir($file_path, $mode = 0777, $recursive = true)
    {
        $dir_path = pathinfo($file_path, PATHINFO_DIRNAME);

        return static::makeDir($dir_path, $mode, $recursive);
    }

}